package com.atguigu.spzx.manager.controller;



import com.atguigu.spzx.manager.service.ProductSpecService;
import com.atguigu.spzx.model.entity.product.ProductSpec;
import com.atguigu.spzx.model.vo.common.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LT
 * @create 2024-03-18-16:57
 */
@RestController
@Tag(name = "商品规格管理")
@RequestMapping("/admin/product/spec")
public class ProductSpecController {

    @Resource
    ProductSpecService productSpecService;

    @GetMapping("/list/{pageNum}/{pageSize}")
    public Result GetProductSpecs(@PathVariable("pageNum")Integer pageNum,
                                 @PathVariable("pageSize") Integer pageSize){
        PageInfo<ProductSpec> pageInfo = productSpecService.GetProductSpecs(pageNum,pageSize);
        return Result.ok(pageInfo);
    }

    @GetMapping("/list")
    public Result GetAllProductSpec(){
        List<ProductSpec> list = productSpecService.GetAllProductSpec();
        return Result.ok(list);
    }

    @GetMapping("/getById/{id}")
    public Result GetProductSpecById(@PathVariable("id") Long id){
        ProductSpec productSpec = productSpecService.GetProductSpecById(id);
        return Result.ok(productSpec);
    }

    @PutMapping("/update")
    public Result UpdateProductSpec(@RequestBody ProductSpec productSpec){
        productSpecService.UpdateProductSpec(productSpec);
        return Result.ok();
    }

    @DeleteMapping ("/delete/{id}")
    public Result DeleteProductSpec(@PathVariable("id") Long id){
        productSpecService.DeleteProductSpec(id);
        return Result.ok();
    }

    @PostMapping("/save")
    public Result SaveProductSpec(@RequestBody ProductSpec productSpec){
        productSpecService.SaveProductSpec(productSpec);
        return Result.ok();
    }

}
